<?php
require 'Home/Controller/Controller.php ';
require 'Home/Model/IndexModel.php ';
class IndexController extends Controller{
	function __Construct(){
		parent::__Construct();
		//$this->mod = 'users';
	}
	function index(){
		$model=new IndexModel();
		$this->assign('newstype',$model->getType());
		$this->assign('news',$model->showNews());
		//$this->assign('downtimes',$model->downTimes());
		$this->assign('hittimes',$model->getRank());

		$this->display(); 
		//return $data;
	}
	function login(){
		$data=$_POST;
		//var_dump($data);
		$model = new IndexModel();
		$result = $model->getUserLogin($data);
		

		$uname=$result['uname'];
		$uid=$result['uid'];

			//引用session
			 $_SESSION["uname"]=$uname;
       		// $_SESSION["password"]=$password;
       		// $_SESSION["userpic"]=$userpic;
       		 $_SESSION["uid"]=$uid;
       		 //$_SESSION["gender"]=$gender;
       		 //$_SESSION["birthdate"]=$birthdate;
       		 //$_SESSION["intro"]=$intro;



		if($result)
		{
			echo '登录成功 <a href="index.php?c=index&m=index">如果没有跳转，请点这里跳转</a>';
   			header("refresh:3;url='index.php?c=index&m=index'");
		}
		else{
			echo "登录失败！<br/>";
  			echo "<a href='index.php?c=index&m=index'>返回</a>";
		}
	}
	
	function logout(){
             session_start();
             session_destroy();
       		 echo "注销成功";
       		 header("refresh:2;url='index.php?c=index&m=index'");


		}

		function addcomments(){
			$data=$_POST;
			$nid=$data['nid'];
			$model=new IndexModel();
			$result=$model->addcomments($data);

			switch ($nid) {
				case '1':
			if ($result) {
				echo "评论成功，3秒后返回首页";
				header("refresh:3;url='index.php?c=index&m=index'");
					}else{
				echo "评论失败，3秒后返回首页";
				header("refresh:3;url='index.php?c=index&m=index'");
					}
					break;
				
				default:
				if ($result) {
				echo "评论成功，3秒后返回该条新闻";
				header("refresh:3;url='index.php?c=show&m=show&nid=$nid'");
					}else{
				echo "评论失败，3秒后返回该条新闻";
				header("refresh:3;url='index.php?c=show&m=show&nid=$nid'");
					}
					break;
			}
/*
			if ($result) {
				echo "评论成功，3秒后返回该条新闻";
				header("refresh:3;url='index.php?c=show&m=show&nid=$nid'");
			}else{
				echo "评论失败，3秒后返回该条新闻";
				header("refresh:3;url='index.php?c=show&m=show&nid=$nid'");
			}*/

		}
		function adduser(){
		$data = $_POST;
		$model = new IndexModel();
		$result = $model->add($data);
		if($result){
			echo '注册成功 <a href="index.php?c=index&m=index">如果没有跳转，请点这里跳转</a>';
   			header("refresh:3;url='index.php?c=index&m=index'");

		}
		else{
			echo "注册失败！<br/>";
  			echo "<a href='index.php?c=index&m=index'>返回</a>";
		}
}
	}
/*	function nav(){
		$model=new $model = new IndexModel();
		$data = $model->getType();
		$this->assign('type',$data);
		$this->display();

	}
	*/

?>